﻿using DX;
using DX.IO;
using DX.ViewModels;
using System;
using System.Drawing;
using System.IO;
using System.Threading.Tasks;
using Tools.Plugins.IconConver.Views;

namespace Tools.Plugins.IconConver.ViewModels
{
    [ViewType(typeof(ReadIconViewControl))]
    public partial class ReadIconViewModel : ViewModel
    {

        public ReadIconViewModel(IFileSystemDialog fileSystemDialog)
        {
            this._fileSystemDialog = fileSystemDialog;
            iconService = new IconService();
        }
        readonly IconService iconService;
        private readonly IFileSystemDialog _fileSystemDialog;
        [CommunityToolkit.Mvvm.ComponentModel.ObservableProperty]
        ImageEntry[] _imgs;
        [CommunityToolkit.Mvvm.Input.RelayCommand]
        private async Task OpenFile()
        {
            FileEntry file = await _fileSystemDialog.OpenSingleFile("Icon(.ico)|*.ico");
            if (file == null)
            {
                return;
            }
            Imgs = iconService.ReadIconToImages(file.GetBuffer());
        }

    }

}
